<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>继承</title>
  </head>
  <body>
    <script>
      /***
         继承
         1.传统模式--原型链
         2.借用构造函数 call/apply
         3.共享原型
         4.圣杯模式
        ***/

      //共享原型
      //父子原型指向相同空间，父子改动都会影响原型链
      /**
         son.prototype赋值会影响到father.prototype
        **/
      Father.prototype.lastName = "HUANG";
      function Father() {}
      function Son() {}
      //共享原型
      function inheritFather(Target, Origin) {
        Target.prototype = Origin.prototype; //共用一个原型
      }
      inheritFather(Son, Father);
      var son = new Son();
      var father = new Father();

      //圣杯模式（继承最终模式）
      //通过中间层,解决共享模型的问题，继承后不影响父级原型
      //通过添加属性记住父级原型
      Mother.prototype.lastName = "han";
      function Mother() {}
      function Daugther() {}
      function inheritMother(Target, Origin) {
        function F() {}
        F.prototype = Origin.prototype;
        Target.prototype = new F();
        //保留子集的构造函数
        Target.prototype.constuctor = Target;
        //新建属性保留父级的构造函数
        Target.prototype.uber = Origin.prototype;
      }

      var inherit = (function () {
        var f = function () {};//闭包私有化变量
        return function (Target, Origin) {
          f.prototype = Origin.prototype;
          Target.prototype = new f();
          //保留子集的构造函数
          Target.prototype.constuctor = Target;
          //新建属性保留父级的构造函数
          Target.prototype.uber = Origin.prototype;
        };
      })();
    //   inheritMother(Daugther, Mother);
      inherit(Daugther,Mother)
      var monther = new Mother();
      var daugther = new Daugther();
    </script>
  </body>
</html>
